package com.cljz.makepassenger.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.GetTypeListBean;
import com.cljz.makepassenger.ui.holder.PicTypeHolder;

import java.util.List;

/**
 * Created by apple on 2017/5/15.
 */

public class PicTypeAdapter extends RecyclerView.Adapter<PicTypeHolder> {

    private Context context;
    private List<GetTypeListBean.DataBean> dataBeanList;
    private OnItemClickListener mOnItemClickListener;


    public void setData(List<GetTypeListBean.DataBean> dataBeanList) {
        this.dataBeanList = dataBeanList;
        notifyDataSetChanged();
    }

    public PicTypeAdapter(Context context, List<GetTypeListBean.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    @Override
    public PicTypeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new PicTypeHolder(View.inflate(context, R.layout.item_pic_type,null));
    }

    @Override
    public void onBindViewHolder(PicTypeHolder holder, final int position) {
        holder.setData(dataBeanList,position);
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickListener.onClick(dataBeanList,position);
                }
            });
            holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View view) {
                    mOnItemClickListener.onLongClick(dataBeanList,position);
                    return false;
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return dataBeanList == null ? 0 : dataBeanList.size();
    }

    public interface OnItemClickListener {
        void onClick(List<GetTypeListBean.DataBean> typeList, int position);

        void onLongClick(List<GetTypeListBean.DataBean> typeList, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }
}
